using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using DAL;
using ORMapping;
using PublicCommon;
using System.Windows.Forms;
using System.Data;

namespace BLL
{
    public class MemberInfoBLL
    {
        public Int32 AddMemberInfo(ref MemberInfo mi)
        {
            MemberInfoDAL mid = new MemberInfoDAL();
            mi.MemberName = mi.MemberName.ToUpper();
            mi.UpdateDate = DateTime.Now;
            mi.UserID = HYSession.Session.GetValue(typeof(User).Name) as User;
            mi.RegisterDate = mi.UpdateDate;
            return mid.AddMemberInfo(mi);
        }

        public DataTable GetAllMemberinfos(String strFormName, Control.ControlCollection cc)
        {
            List<DAL.HQLParameter> hp = new List<DAL.HQLParameter>();
            string strHQL = "from MemberInfo M ";
            Functions.QueryWhere(strFormName,cc, ref hp, ref strHQL);
            MemberInfoDAL dal = new MemberInfoDAL();
            return NHibernateHelper.Convert.ConvertToDataTable<MemberInfo>(dal.GetAllMemberInfos(strHQL, hp));
        }

        public Int32 AddMemberInfo(Control.ControlCollection cc)
        {
            MemberInfo mi = new MemberInfo();
            BLLHelper.SetMappingValue(mi, cc);
            MemberInfoDAL mid = new MemberInfoDAL();
            return AddMemberInfo(ref mi);
        }

        public void UpdateMemberInfo(ref DataRow drMemberInfo, Control.ControlCollection cc)
        {
            MemberInfo mi = new MemberInfo();
            BLLHelper.SetMappingValue(mi, cc);
            UpdateMemberInfo(ref mi);
            BLLHelper.SetControlToDataRow(ref drMemberInfo, cc);
        }

        public void UpdateMemberInfo(ref MemberInfo mi)
        {
            mi.UpdateDate = DateTime.Now;
            mi.UserID = HYSession.Session.GetValue(typeof(User).Name) as User;
            MemberInfoDAL mid = new MemberInfoDAL();
            mid.UpdateMemberInfo(mi);
        }

        public MemberInfo GetMemberInfoByNameMobilePhone(MemberInfo mi)
        {
            MemberInfoDAL mid = new MemberInfoDAL();
            return mid.GetMemberInfoByNameMobilePhone(mi);            
        }

        public IList<MemberInfo> GetMemberInfoByName(String MemberName)
        {
            MemberInfoDAL mid = new MemberInfoDAL();
            return mid.GetMemberInfoByName(MemberName);
        }

        public MemberInfo GetMemberInfoByID(Int32 MemberID)
        {
            MemberInfoDAL mid = new MemberInfoDAL();
            return mid.GetMemberInfoByID(MemberID);
        }
    }
}
